﻿namespace IceDog.DNC.Library.Standard.Permisssion.Red
{
    /// <summary>
    /// 通过与或非运算符实现权限
    /// </summary>
    public class PermissionItem:IPermissionAction<PermissionType>
    {
        public int Permission { get; set; }
        public int AddPermission(PermissionType permission)
        {
            this.Permission = (this.Permission | (int)permission);
            return Permission;
        }

        public int RemovePermission(PermissionType permission)
        {
            if (!HasPermission(permission))
            {
                return Permission;
            }
            this.Permission = (this.Permission ^ (int)permission);
            return Permission;
        }

        public bool HasPermission(PermissionType permission)
        {
            var p = (int) permission;
            return (this.Permission & p) == p;
        }
    }
}
